// 220110 2012

// 路由
// 提取出请求的 URL 以及 GET/POST 参数
// request 对象, onRequest() 回调函数
// url 和 querystring 模块

var http = require('http');
var url = require('url');

function start() {
	function onRequest(request, response) {
		var pathname = url.parse(request.url).pathname;
		console.log('request.url=' + request.url);
		console.log('pathname=' + pathname);
		
		// 返回
		// response.writeHead(200, {"Content-Type": "text/plain"});
		
		// 解决中文乱码
		response.writeHead(200, {"Content-Type": "text/plain; charset=utf-8"});
		
		response.write('服务器时间：' + new Date());
		response.end();
	}
	
	var sport = 8888;
	http.createServer(onRequest).listen(sport);
	console.log('Server has started on port#' + sport);
}

exports.start = start;
